package nullby.yoga.utils;

import nullby.yoga.R;
import android.content.Context;
import android.content.SharedPreferences;
import android.media.AudioManager;
import android.media.SoundPool;

public class SoundManager {

	private static SoundManager instance;

	private static int click;
	private static int check;

	private static SoundPool pool = new SoundPool(2, AudioManager.STREAM_MUSIC,
			0);

	private SoundManager(Context mContext) {
		if (instance == null) {
			click = pool.load(mContext, R.raw.click, 1);
			check = pool.load(mContext, R.raw.check, 1);
		}
	}

	public static SoundManager getInstance() {
		return instance;
	}

	public static SoundManager newInstance(Context context) {
		if (instance == null) {
			instance = new SoundManager(context);
		}
		return instance;
	}

	public void clear() {
		if (pool != null) {
			pool.release();
			pool = null;
			check = -1;
			click = -1;
		}
	}

	public void playCheckSetting() {
		pool.play(check, 1.0F, 1.0F, 1, 0, 1.0F);
	}

	public void playCheck() {
		if (isSound()) {
			pool.play(check, 1.0F, 1.0F, 1, 0, 1.0F);
		}
	}

	public void playClick() {
		if (isSound()) {
			pool.play(click, 1.0F, 1.0F, 1, 0, 1.0F);
		}
	}

	public Boolean isSound() {
		return PrefManager.get().isButtonSound();
	}

}
